<template>
<el-row>
    <el-row>
    <!--新增/编辑界面 Category 档案类目-->
        <el-form :model="editForm"  label-width="120px" :rules="editFormRules" ref="editFormRef">
            <el-form-item label="分类主题" prop="categoryType">
                <mdp-select item-code="categoryType" show-style="origin" v-model="editForm.categoryType" placeholder="主题" :maxlength="1" @change="editSomeFields(editForm,'categoryType',$event)" :disabled="disabledJudge('categoryType')||(currOpType.indexOf('add')<0)"/>
            </el-form-item>
            <el-form-item label="分类编号" prop="id">
                <el-input show-style="origin" v-model="editForm.id" placeholder="分类编号" :maxlength="50" @change="editSomeFields(editForm,'id',$event)" :disabled="disabledJudge('id')||(currOpType.indexOf('add')<0)"/>
            </el-form-item>
            <el-form-item label="分类名称" prop="name">
                <el-input show-style="origin" v-model="editForm.name" placeholder="分类名称" :maxlength="50" @change="editSomeFields(editForm,'name',$event)" :disabled="disabledJudge('name')"/>
            </el-form-item>
            <el-form-item label="分类排序" prop="sortOrder">
                <mdp-number show-style="origin" v-model="editForm.sortOrder" placeholder="分类排序" :maxlength="5" :disabled="disabledJudge('sortOrder')"/>
            </el-form-item>
            <el-form-item label="是否显示" prop="isShow">
                <el-checkbox v-model="editForm.isShow" true-label="1" false-label="0" @change="editSomeFields(editForm,'isShow',$event)" :disabled="disabledJudge('isShow')">是否显示</el-checkbox> 
             </el-form-item>
            <el-form-item label="叶子节点" prop="isLeaf">
                <el-checkbox v-model="editForm.isLeaf" true-label="1" false-label="0" @change="editSomeFields(editForm,'isLeaf',$event)" :disabled="disabledJudge('isLeaf')">是否叶子节点,叶子节点不允许再建立下级，非叶子节点不允许挂文章</el-checkbox> 

             </el-form-item> 
            <el-form-item label="文章审核" prop="isAuth">
                <el-checkbox v-model="editForm.isAuth" true-label="1" false-label="0" @change="editSomeFields(editForm,'isAuth',$event)" :disabled="disabledJudge('isAuth')">文章是否需要审核</el-checkbox> 

             </el-form-item>
            <el-form-item label="文章限制" prop="limitType">
                 <el-checkbox v-model="editForm.limitType" auto-complete="off"  true-label="1" false-label="2" @change="editSomeFields(editForm,'limitType',$event)" :disabled="disabledJudge('limitType')">文章数目是否限制为1篇</el-checkbox>

             </el-form-item>

            <el-form-item label="上级编号" prop="pid">
                <el-input show-style="origin" v-model="editForm.pid" placeholder="上级分类" :maxlength="50" @change="editSomeFields(editForm,'pid',$event)" :disabled="disabledJudge('pid')||true"/>
            </el-form-item>
            <el-form-item label="机构编号" prop="branchId">
                <el-input show-style="origin" v-model="editForm.branchId" placeholder="机构编号" :maxlength="50" @change="editSomeFields(editForm,'branchId',$event)" :disabled="disabledJudge('branchId')||true"/>
            </el-form-item>
            <el-form-item label="图片列表" prop="imageUrls">
                <el-input show-style="origin" v-model="editForm.imageUrls" placeholder="图片列表逗号分割" :maxlength="1024" @change="editSomeFields(editForm,'imageUrls',$event)" :disabled="disabledJudge('imageUrls')"/>
            </el-form-item>
            <el-form-item label="上级分类路径" prop="paths">
                <el-input show-style="origin" v-model="editForm.paths" placeholder="上级分类路径，逗号分割，包括自身" :maxlength="255" @change="editSomeFields(editForm,'paths',$event)" :disabled="disabledJudge('paths')||true"/>
            </el-form-item>
        </el-form>
    </el-row>
    <slot name="footer" :page="this">
        <el-row v-if="showBtn!==false" style="float:right;" class="footer">
            <el-button @click.native="close">关闭</el-button>
            <el-button v-if="currOpType=='add'" v-loading="load.edit" type="primary" @click.native="saveSubmit" :disabled="disabledJudge('addBtn') || !checkBtnQx('addBtn',menuDefId) || load.edit">提交</el-button>
        </el-row>
    </slot>
</el-row>
</template>

<script>
import * as CategoryApi from '@/api/mdp/arc/pub/category';
import { mapGetters } from 'vuex'
import { MdpFormMixin } from '@/components/mdp-ui/mixin/MdpFormMixin.js';

export default {
    name:'categoryForm',
    mixins:[MdpFormMixin],
    components: {
    },
    computed: {
    },
    props:{
    },
    watch: {
    },
    data() {
        return {
            menuDefId:'',//menu_def.id 菜单表菜单编号，用于按钮权限判断
            pkNames:["id"],//表格主键的java属性名称，驼峰命名，默认为id,支持多主键
            currOpType:'add',//表单 add、edit，所有按钮可动、detail-只看不能操作
            editFormRules: {
                name:[
                    { required: true, message: '此项必填', trigger: 'change' }, 
                ],
                categoryType:[
                    { required: true, message: '此项必填', trigger: 'change' }, 
                ]
            },
            editForm: {
                categoryType:'',id:'',pid:'',name:'',sortOrder:'',isShow:'',branchId:'',imageUrls:'',isLeaf:'',limitType:'',isAuth:'',paths:''
            },
            //增删改查(含批量)接口
            apis:{
                queryById: CategoryApi.queryCategoryById,
                add: CategoryApi.addCategory,
                edit: CategoryApi.editCategory,
                editSomeFields: CategoryApi.editSomeFieldsCategory
            }
        }
    },
    methods: {
         //由组件扩展添加其它的初始页面的逻辑(mounted+onOpen都会调用此函数，建议只添加公共逻辑)
         initCurrData(){

         },
        /**
         * 检查参数是否满足调用后台接口的条件
         * @returns true / false
         */
        preParamCheck(params){
            return true;
        },

        /**
          * 设置某个关键词、按钮、输入框禁用 disabledRules['addBtn']=false
          * 判断某个对象是否可编辑 this.disabledJudge('addBtn')==false
          */
        disabledRulesInit(disabledRules){

        },
        /**
         * 对修改的字段进行判断，返回false ,将取消更新数据库,由组件扩展
         * @param {*} row 当前选中的行
         * @param {*} fieldName 修改的字段名
         * @param {*} $event 修改后的值
         * @param {*} params 将要提交服务器的参数
         * @returns true/false 返回false ,将取消更新数据库
         */
        editSomeFieldsCheck(row,fieldName,$event,params){
            params[fieldName]=$event
            return true;
        },
    },
    mounted() {

    }
}

</script>

<style scoped>

</style>